﻿using System;
using System.Collections;

using System.Text;
using System.IO;

using CF.Data;

namespace CF.Service
{

  public   class StepByStep
    {
     
     
      public void Step1_CreateDatabase()
      {
          string path = AppDomain.CurrentDomain.BaseDirectory;
          if (path[path.Length - 1] != '\\') path = path + "\\";
          //new MssqlHelper("").CreateTableAndViewScript(path+"CF.Data.dll",null);
        //  new PgsqlHelper("").CreateTableAndViewScript(path + "Demo.Data.dll", "d:/db.sql");
          
      }

      public void Step4_CreateRelations()
      {
          //IDataAccess<TColumn, string> dao1 = new DAO<TColumn, string>();
          //TColumn cl = new TColumn(); cl.ProjectName = "SP"; cl.TableName = "Product"; cl.NameCN = "NameCN"; cl.Lenth = "50";
          //cl.Memo = ""; cl.Type = "nvarchar";
          //dao1.Save(cl);

      }

      public static string LoadFileToArrayList(string LoadFromHere)
      {
          //ArrayList ReturnArrayList = new ArrayList();
          string jStr = string.Empty;
          try
          {
              StreamReader LoadFrom = new StreamReader(@LoadFromHere.Trim(), Encoding.GetEncoding("UTF-8"));
              //LoadFrom = File.OpenText(@LoadFromHere.Trim());

              while (LoadFrom.Peek() != -1)
              {
                  //ReturnArrayList.Add(LoadFrom.ReadLine());
                  jStr += LoadFrom.ReadLine();
              }
              LoadFrom.Close();
          }
          catch
          {
              Console.WriteLine("载入文件" + @LoadFromHere + "失败");
              System.Console.ReadLine();
              //ReturnArrayList.Clear();
          }


          return jStr;
          //return ReturnArrayList;
      }

      //函数名：LoadTenToArrayList(已完成)
      //简  述：载入文件中前33个数据到列表
      //返回值：ArrayList
      //参数一：string，即要载入内存的文件路径
      //注  释：
      //注  意：
      public static ArrayList LoadPartFileToArrayList(string LoadFromHere)
      {
          ArrayList ReturnArrayList = new ArrayList();
          StreamReader LoadFrom;

          try
          {
              LoadFrom = File.OpenText(LoadFromHere.Trim());
          }
          catch
          {
              Console.WriteLine("载入文件" + @LoadFromHere + "失败");
              System.Console.ReadLine();
              return ReturnArrayList;
          }
          int i = 0;
          while (LoadFrom.Peek() != -1)
          {
              i = i + 1;
              if (i < 34)
              {
                  ReturnArrayList.Add(LoadFrom.ReadLine());
              }
              else
              {
                  break;
              }
          }

          LoadFrom.Close();

          return ReturnArrayList;
      }

      //函数名：WriteToFile(已完成)
      //简  述：将ArrayList写入文件
      //返回值：bool
      //参数一：ArrayList，要写入
      //参数二：string，到这儿
      //注  释：
      //注  意：        
      public static bool WriteToFile(ArrayList WaitWrite, string WriteTo)
      {
          StreamWriter MyWriteTo;
          try
          {
              MyWriteTo = File.CreateText(WriteTo.Trim());
          }
          catch
          {
              return false;
          }

          foreach (string curstr in WaitWrite)
          {
              MyWriteTo.WriteLine(curstr);
          }

          MyWriteTo.Close();
          return true;

      }
      
    }
}
